<?php /** @var BootActiveForm $form */
$form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array(
    'id'=>'create-activity',
    'type'=>'horizontal',
    'enableClientValidation'=>true,
    'clientOptions'=>array(
        'validateOnSubmit'=>true,
    ),
)); ?>
 
<fieldset>
 
    <legend><?php echo $model->isNewRecord ? '新增'.ActivityType::$names[$model->activity_type] : '修改'.ActivityType::$names[$model->activity_type] ?></legend>
    <?php echo $form->errorSummary($model); ?>
    <?php echo $form->textFieldRow($model, 'activity_name'); ?>
    <?php echo $form->dropDownListRow($model, 'activity_type', ActivityType::$names, array('disabled'=>true)); ?>    
    <?php echo $form->dropDownListRow($model, 'mapred_type', MapRedType::$names); ?>    
    <?php echo $form->textFieldRow($model, 'retry_times'); ?>
    <legend>
    <small>定义输入
    <?php echo CHtml::ajaxLink('<i class="icon-plus"></i>添加', $this->createUrl('activity/addInput'), array(
        'success'=>'js: function(data) {
            $("#inputs").append(data);
        }',
    )); ?>
    </small>
    </legend>
    <div id="inputs">
        <?php 
        if($model->isNewRecord) {
            $inputForm = new InputForm();
            $inputForm->partition = '{0, 1 day}';
            $inputForm->input_type = ResourceType::Log;
            $model->inputs = array($inputForm);
        }

        foreach($model->inputs as $input) {
            echo $this->renderPartial('_mrinput', array('model'=>$input));
        } 
        ?>
    </div>
    
    <legend><small>定义输出</small></legend>
    <div id="outputs">
        <?php
        if($model->isNewRecord) {
            $outputForm = new OutputForm();
            $model->outputs = array($outputForm);
        }
        foreach($model->outputs as $output) {
            echo $form->textFieldRow($output, 'output_name', array('hint'=>'遵循变量命名，请先'.CHtml::ajaxLink('检查唯一性',$this->createUrl('activity/checkOutput'),array(
                        'type'  =>  'POST',
                        'success'=>'js:function(data) {alert(data);}',
                    ))
                )); 
            echo $form->textFieldRow($output, 'output_desc'); 
            echo $form->dropDownListRow($output, 'output_freq', Frequency::$names); 
            echo $form->checkBoxRow($output, 'output_multiple'); 
        }
        ?>
    </div>
    <legend><small>程序及参数</small></legend>
    <div id="programs">
        <?php echo $form->textFieldRow($model, 'jar', array('class'=>'span7')); ?>
        <?php echo $form->textFieldRow($model, 'map', array('class'=>'span7')); ?>
        <?php echo $form->textFieldRow($model, 'reduce', array('class'=>'span7')); ?>
    </div>
    <div id="params">
        <?php
        if($model->isNewRecord) {
            $model->params = new ParamForm;
        }
        ?>
        <?php echo $form->textFieldRow($model->params, 'input_format', array('class'=>'span6','placeholder'=>'-inputformat ')); ?>
        <?php echo $form->textFieldRow($model->params, 'output_format', array('class'=>'span6','placeholder'=>'-outputformat')); ?>
        <?php echo $form->textFieldRow($model->params, 'partitioner', array('class'=>'span6','placeholder'=>'-partitioner')); ?>
        <?php echo $form->textAreaRow($model->params, 'other_define', array('class'=>'span6', 'rows'=>5, 'hint'=>'<strong>注意:</strong> 提交参数-D, -file, -cacheFile, -cacheArchive在此定义.')); ?>
    </div>
</fieldset>
<div class="form-actions">
    <?php $this->widget('bootstrap.widgets.TbButton', array('buttonType'=>'submit', 'type'=>'primary', 'icon'=>'ok white', 'label'=>$model->isNewRecord ? '创 建' : '保 存')); ?>
    <?php $this->widget('bootstrap.widgets.TbButton', array('buttonType'=>'reset', 'icon'=>'remove', 'label'=>'取 消')); ?>
</div>
<?php $this->endWidget(); ?>
